package com.hao.editorbox;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.hao.editorview.EditorViewActivity;

public class MainActivity extends AppCompatActivity {

    public static final int COMMENT_STATE = 1000;

    private TextView conent;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        conent = (TextView) findViewById(R.id.common_content);
        findViewById(R.id.common_comment).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String content = conent.getText() + "";
                if (TextUtils.isEmpty(content))
                    skipCommon("");
                else skipCommon(content);
            }
        });
    }


    private void skipCommon(String content) {
        Bundle bundle = new Bundle();
        bundle.putString("content", content);
        Intent intent = new Intent(MainActivity.this, EditorViewActivity.class);
        intent.putExtras(bundle);
        startActivityForResult(intent, COMMENT_STATE);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (resultCode != Activity.RESULT_OK)
            return;
        if (COMMENT_STATE == requestCode) {
            String content = data.getStringExtra("content");
            boolean isCommon = data.getBooleanExtra("isComment", false);
            conent.setText(content);
        }
    }
}
